﻿CREATE VIEW [dbo].[ASMS_V_Stock]
	AS
select M.Id as MaterialId,
	M.[Name] as MaterialName,
	M.[Code] as MaterialCode,
	M.[Cost] as MaterialCost,
	M.[Price] as MaterialPrice,
	M.[Category] as MaterialCategory,
	MDIC.Name as MaterialCategoryName,
	MDIU.Name as MaterialUnitName,
	S.[Id]	as [Id],
	S.[Count] as [Count],
	S.[Cost] as [Cost],
	S.[AverageCost] as StockAverageCount,
	WH.Id as WarehouseId,
	WH.Name as WarehouseName,
	WH.BusinessId, 
	WH.StationId
 from ASMS_Stock as S 
left join ASMS_Material as M on M.Id = S.MaterialId
left join ASMS_Warehouse as WH on WH.Id = S.WarehouseId
left join [ASMS_MasterDataItem] as MDIC on MDIC.Code = M.Category
left join [ASMS_MasterDataItem] as MDIU on MDIU.Code = M.Unit

--select M.Id as MaterialId,
--	M.[Name] as MaterialName,
--	M.[Code] as MaterialCode,
--	M.[Cost] as MaterialCost,
--	M.[Price] as MaterialPrice,
--	M.[Category] as MaterialCategory,
--	MDIC.Name as MaterialCategoryName,
--	MDIU.Name as MaterialUnitName,
--	S.[Id]	as [Id],
--	S.[Count] as [Count],
--	S.[Cost] as [Cost],
--	S.[AverageCost] as StockAverageCount,
--	WH.Id as WarehouseId,
--	WH.Name as WarehouseName
-- from asms_material as M
--left join asms_stock as S on S.MaterialId = M.Id
--left join ASMS_warehouse as WH on WH.Id = S.WarehouseId
--left join ASMS_MDItem as MDIC on MDIC.Code = M.Category
--left join ASMS_MDItem as MDIU on MDIU.Code = M.Unit
